-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Remove redundancy from the implementation of C variadics. #63492
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Great stuff! This is much cleaner.
@@ -2102,7 +2097,14 @@ impl<'a> LoweringContext<'a> { | |||
} | |||
|
|||
fn lower_fn_args_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> { | |||
decl.inputs | |||
// Skip the `...` (`CVarArgs`) trailing arguments from the AST, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea to skip this here.
8b9d92c
to
f6d4b3b
Compare
☔ The latest upstream changes (presumably #63655) made this pull request unmergeable. Please resolve the merge conflicts. |
cc @matthewjasper @nikomatsakis for the MIR changes |
Ping from triage, can someone from @rust-lang/compiler review this PR. Thanks |
Ping from triage |
Ping from Triage: Closing due to inactivity. If or when there are updates, please re-open. @eddyb Thanks for the PR. |
@eddyb overall r=me, with the two nits fixed. |
va_list.layout.ty, | ||
scope, | ||
variable_access, | ||
VariableKind::ArgumentVariable(arg_index + 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this one too far? arg_index
is already one beyond the list of normal arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ 1
is pre-existing, I'm not sure what the deal is (see my comment on this in some of the prereq commits in #56231).
@@ -1100,8 +1100,26 @@ fn check_fn<'a, 'tcx>( | |||
let outer_hir_id = fcx.tcx.hir().as_local_hir_id(outer_def_id).unwrap(); | |||
GatherLocalsVisitor { fcx: &fcx, parent_id: outer_hir_id, }.visit_body(body); | |||
|
|||
// C-variadic fns also have a `VaList` input that's not listed in `fn_sig` | |||
// (as it's created inside the body itself, not passed in from outside). | |||
let maybe_va_list = if fn_sig.c_variadic { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost the same code snippet appears in src/librustc_mir/build/mod.rs
factor out into a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to open an issue but I think there is a more general problem here and it also involves the whole liberated_fn_sigs
.
That is, there should be a common way to get the "function signature as viewed from inside the body" - possibly including reading the types associated with the hir::Body
arguments as opposed to computing them from tcx.fn_sig(def_id)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point is, I don't want a shared function for just the c_variadic
part of this.
Failed in #64860 (comment), @bors r- |
@bors retry |
@bors r- r? @matthewjasper for the MIR/NLL borrowck (I had to redo it, first attempt was flawed) |
@bors r=nagisa,matthewjasper |
📌 Commit 057f23d has been approved by |
Remove redundancy from the implementation of C variadics. This cleanup was first described in rust-lang#44930 (comment): * AST doesn't track `c_variadic: bool` anymore, relying solely on a trailing `CVarArgs` type in fn signatures * HIR doesn't have a `CVarArgs` anymore, relying solely on `c_variadic: bool` * same for `ty::FnSig` (see tests for diagnostics improvements from that) * `{hir,mir}::Body` have one extra argument than the signature when `c_variadic == true` * `rustc_typeck` and `rustc_mir::{build,borrowck}` need to give that argument the right type (which no longer uses a lifetime parameter, but a function-internal scope) * `rustc_target::abi::call` doesn't need special hacks anymore (since it never sees the `VaListImpl` now, it's all inside the body) r? @nagisa / @rkruppe cc @dlrobertson @oli-obk
Rollup of 5 pull requests Successful merges: - #63492 (Remove redundancy from the implementation of C variadics.) - #64589 (Differentiate AArch64 bare-metal targets between hf and non-hf.) - #64799 (Fix double panic when printing query stack during an ICE) - #64824 (No StableHasherResult everywhere) - #64884 (Add pkg-config to dependency list if building for Linux on Linux) Failed merges: r? @ghost
Rustup rust-lang/rust#63492 changelog: none
This cleanup was first described in #44930 (comment):
c_variadic: bool
anymore, relying solely on a trailingCVarArgs
type in fn signaturesCVarArgs
anymore, relying solely onc_variadic: bool
ty::FnSig
(see tests for diagnostics improvements from that){hir,mir}::Body
have one extra argument than the signature whenc_variadic == true
rustc_typeck
andrustc_mir::{build,borrowck}
need to give that argument the right type (which no longer uses a lifetime parameter, but a function-internal scope)rustc_target::abi::call
doesn't need special hacks anymore (since it never sees theVaListImpl
now, it's all inside the body)r? @nagisa / @rkruppe cc @dlrobertson @oli-obk